/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package shogi.pieces;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import shogi.ShogiBoard;

/**
 *
 * @author p_polu
 */
public abstract class Piece extends JLabel implements PieceInterface {

    private ImageIcon icon;
    private String orientation;
    private boolean promoted;
    private int index;
    private char type;

    public Piece() {
        super();
    }

    public Piece(int index, char type, String orientation) {
        this.index = index;
        this.orientation = orientation;
        this.type = type;
        this.icon = new ImageIcon(getClass().getResource("../" + ShogiBoard.getIconSetDirectory() + type + orientation + ".png"));
        this.setIcon(icon);
    }

    @Override
    public String getOrientation() {
        return orientation;
    }

    @Override
    public void setOrientation(String orientation) {
        this.orientation = orientation;
    }

    @Override
    public int getIndex() {
        return index;
    }

    @Override
    public void setIndex(int index) {
        this.index = index;
    }

    @Override
    public int getRow() {
        return (this.getIndex() / 9);
    }

    @Override
    public int getColumn() {
        return (this.getIndex() % 9);
    }

    @Override
    public char getType() {
        return type;
    }

    @Override
    public void setType(char type) {
        this.type = type;
    }

    @Override
    public String getLongType() {
        switch (this.type) {
            case 'p':
                return "pawn";
            case 'l':
                return "lance";
            case 'n':
                return "knight";
            case 's':
                return "silver";
            case 'g':
                return "gold";
            case 'k':
                return "king";
            case 'b':
                return "bishop";
            case 'r':
                return "rook";
            default:
                return null;
        }
    }

    @Override
    public boolean isPromoted() {
        return promoted;
    }

    @Override
    public void setPromoted(boolean promoted) {
        this.promoted = promoted;
    }

    public boolean isMoveLegal(int originalRow,
            int originalColumn, int destinationRow, int destinationColumn) {

        throw new Error();

    }

    public abstract int getIntValue();
}
